<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Tenmillionproject extends Backend
{

    /**
     * Millionproject模型对象
     * @var \app\admin\model\Tenmillionproject
     */
    protected $model = null;
    protected $tmpFields = [];
    protected $tmpFieldNames = [];
    protected $fieldNames = [];

    public function _initialize()
    {
        parent::_initialize();
//        $this->relationtTable = 'street';
        $this->model = new \app\admin\model\Tenmillionproject();
        $this->assignconfig('isSuperAdmin',$this->auth->isSuperAdmin());
        $this->assign('isSuperAdmin',$this->auth->isSuperAdmin());
        if($this->auth->isSuperAdmin())
            $this->pre = '';
        else
            $this->pre = 'tmp_';
        $this->assign('pre',$this->pre);

        $this -> tmpFields = [
            'tmp_scope_business', //经营范围
            'tmp_investment_name', // 投资方名称
            'tmp_investment_area', // 投资方地区
            'tmp_is_out', // 是否市外项目
            'tmp_register_time', //注册时间
            'tmp_investment_total', // 总投资
            'tmp_registered_capital', // 注册资本
            'tmp_industry_type_name', // 产业类型
            'tmp_area', //占地面积
            'tmp_progress_status' //进展状态
        ];

        $this -> tmpFieldNames = [
            'tmp_scope_business' => '经营范围', //经营范围
            'tmp_investment_name' => '投资方名称', // 投资方名称
            'tmp_investment_area' => '投资方地区', // 投资方地区
            'tmp_is_out' => '是否市外项目', // 是否市外项目
            'tmp_register_time' => '注册时间', //注册时间
            'tmp_investment_total' => '总投资', // 总投资
            'tmp_registered_capital' => '注册资本', // 注册资本
            'tmp_industry_type_name' => '产业类型', // 产业类型
            'tmp_area' => '占地或面积', //占地面积
            'tmp_progress_status'=>'进展状态' //进展状态
        ];

        $this -> fieldNames = [
            'scope_business' => '经营范围', //经营范围
            'investment_name' => '投资方名称', // 投资方名称
            'investment_area' => '投资方地区', // 投资方地区
            'is_out' => '是否市外项目', // 是否市外项目
            'register_time' => '注册时间', //注册时间
            'investment_total' => '总投资', // 总投资
            'registered_capital' => '注册资本', // 注册资本
            'industry_type_name' => '产业类型', // 产业类型
            'area' => '占地或面积', //占地面积
            'progress_status'=>'进展状态' //进展状态
        ];

        $investment_type= [
            "" => "请选择",
            "1" => "独资",
            "2" => "合作",
            "3" => "合资"
        ];
        $industry_type= [
            "" => "请选择",
            "1" => "独资",
            "2" => "合作",
            "3" => "合资"
        ];
        $this -> assign('investment_type',$investment_type);
        $this -> assign('industry_type',$industry_type);
        // pr(["" => "请选择"]+getSelectList('chargedep',['group_id'=>5]));
        $this -> assign('streets',["" => "请选择"]+getSelectList('chargedep',['group_id'=>5]));

        $this->chargedep_data = $this->auth->getChargedep();

        if($this->chargedep_data)
        {
            $chargedep_id = $this->chargedep_data->chargedep_id;
            $this->assignconfig('isbinddep',1);
        }
        else
        {
            $chargedep_id = 0;
            $this->assignconfig('isbinddep',0);
        }
    }

    public function index()
    {
        $str = '';
        if(!$this -> auth -> isSuperAdmin()){
            $dep = $this->chargedep_data = $this->auth->getChargedep();
            $streetId = $dep['chargedep_id'];
            $this -> whereExtend = [
                'street_id' => $streetId
            ];
        }else{
            if(!$this -> request -> isPost() && $this -> auth -> isSuperAdmin()){
                $allCount = $this -> model -> count();
                $streetData = $this -> model -> field('street_name,street_id,count(*) as count') -> group('street_id') -> select();
                $overBillion = $this -> model -> field('count(*) as count,sum(investment_total) as total') -> where(['investment_total' => ['egt',10000]]) -> find();
                $str = "截至目前，全区新引进注册1000万以上的内资项目{$allCount}个，其中：";
                $data = [];
                foreach ($streetData as $v){
                    if($v['street_id']){
                        $data[] = $v['street_name'].$v['count']."个";
                    }
                }
                $str .= implode(';',$data);
                $str .= "。投资过亿元大项目{$overBillion['count']}个，累计总投资{$overBillion['total']}万元。";
            }
        }

        $this -> assign('str',$str);
        return parent::index();
    }


    public function add()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");

            if ($params) {
                $params = $this->preExcludeFields($params);

                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
                    $params[$this->dataLimitField] = $this->auth->id;
                }

                // 非管理员需要经过审核
                $insertData = [];
                if(!$this -> auth -> isSuperAdmin()){
                    foreach ($params as $k => &$v) {
                        if($k == 'name') {
                            $insertData['name'] = $v;
                        }

                        $insertData['tmp_'.$k] = $v;
                        unset($params[$k]);
                    }
                    unset($v);
                    $dep = $this->auth->getChargedep();
                    if($dep['group_id'] == 5){
                        $insertData['street_id'] = $dep['chargedep_id'];
                        $insertData['street_name'] = $dep['chargedep_name'];
                    }
                    $insertData['status'] = 100;
                    $params = $insertData ?? $params;
                }

                $result = false;
                Db::startTrans();
                try {
                    //是否采用模型验证
                    if ($this->modelValidate) {
                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
                        $this->model->validateFailException(true)->validate($validate);
                    }
                    $result = $this->model->allowField(true)->save($params);
                    $id = $this -> model -> getLastInsID();

                    //写入日志
                    $logData = [];
                    $row = $this -> model -> find($id);
                    foreach ($this -> tmpFieldNames as $k => $v) {
                        $k = $this -> auth -> isSuperAdmin() ? $this -> ltrim($k) : $k;
                        if(isset($row -> $k)){
                            $logData[] = [
                                'tenmillionproject_id' => $id,
                                'tenmillionproject_name' => $row['name'],
                                'admin_id'  => $this -> auth -> id,
                                'admin_nickname'        => $this -> auth -> nickname,
                                'field' => $this -> ltrim($k),
                                'field_name' => $v,
                                'new_value' => $row -> $k,
                                'status' => 100,
                                'info'  => '项目创建',
                                'create_time' => time(),
                                'update_time'   => time()
                            ];
                        }
                    }

                    Db::name('tenmillionprojectlog') -> insertAll($logData);

                    Db::commit();
                } catch (ValidateException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (PDOException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
                if ($result !== false) {
                    $this->success();
                } else {
                    $this->error(__('No rows were inserted'));
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }


        return $this->view->fetch();
    }

    public function edit($ids = NULL) {
        if(!$ids) $this -> error('请重试');
        $row = $this -> model -> find($ids);

        if($this -> request -> isPost()){
            $data = $this -> request -> post('row/a');
            $updateData = [];
            $logData = [];
            foreach ($data as $k => $v) {
                if(is_array($v)){
                    $data[$k] = implode(',',$v);
                }
                if(isset($row -> $k) && $row -> $k != $data[$k]){


                    if(is_int($row -> $k) && date("Y-m-d",$row -> $k) == $data[$k]) continue;
                    $key = $this -> auth -> isSuperAdmin() ? $k : 'tmp_'.$k;
                    $updateData[$key] = $data[$k];
                    $logData[] = [
                        'tenmillionproject_id' => $row -> id,
                        'tenmillionproject_name' => $row['name'],
                        'admin_id'  => $this -> auth -> id,
                        'admin_nickname'        => $this -> auth -> nickname,
                        'field' => $k,
                        'field_name' => $this -> tmpFieldNames[$k] ?? ($this -> fieldNames[$k] ?? ''),
                        'ori_value' => $row -> $k,
                        'new_value' => $data[$k],
                        'status' => $this -> auth -> isSuperAdmin() ? 300 : 100,
                        'info'  => $this -> auth -> isSuperAdmin() ? '管理员修改' : '申请提交',
                        'create_time' => time(),
                        'update_time'   => time()
                    ];
                }
            }
            Db::name('tenmillionprojectlog') -> insertAll($logData);
            if($updateData){
                if(!$this -> auth -> isSuperAdmin()){
                    $updateData['status'] = 100;
                }
                $ret = $row -> save($updateData);
                $this -> success('成功');
            }else{
                $this -> error('无数据修改');
            }
        }
        $this -> assign('row',$row);
        return $this->view->fetch();
    }

    public function checkedit($ids = null){
        if(!$ids) $this -> error('请重试');
        $row = $this -> model -> find($ids);
        $chargeDepsArr = \app\admin\model\Chargedep::all();
        $chargeDeps = [];
        foreach ($chargeDepsArr as $dep){
            $chargeDeps[$dep -> id] = $dep -> name;
        }

        $this -> assign('row',$row);
        return $this -> fetch();
    }

    public function checkpass($ids = null){
        if(!$ids || !$this -> auth -> isSuperAdmin()) $this -> error('请刷新重试，或者您不是管理员');
        $rows = $this ->model -> whereIn('id',$ids) -> select();
        return $this -> check($rows,'pass');
    }

    public function checkreject($ids = null){
        if(!$ids || !$this -> auth -> isSuperAdmin()) $this -> error('请刷新重试，或者您不是管理员');
        $rows = $this ->model -> whereIn('id',$ids) -> select();
        if($this -> request -> isPost()){
            return $this -> check($rows,'reject');
        }
        $this -> assign('ids',$ids);
        return $this -> fetch();
    }

    /**
     * 一键通过所有
     */
    public function passall(){
        $rows = $this -> model -> where(['status' => 100]) -> select();
        if(!$rows){
            $this -> error('暂无需要审核的项目');
        }
        return $this -> check($rows,'pass');
    }

    private function check($rows = null, $action = null){
        if(!$rows || !$action) $this -> error('请刷新重试');

        $ret = true;
        foreach ($rows as $row){
            if('pass' == $action){

                $checkData = [];
                foreach ($this->tmpFields as $tmpField) {
                    if($row -> $tmpField){
                        $field = $this -> ltrim($tmpField);

                        $checkData[] = [
                            'tenmillionproject_id'  => $row['id'],
                            'tenmillionproject_name'    => $row['name'],
                            'admin_id'              => $this -> auth -> id,
                            'admin_nickname'        => $this -> auth -> nickname,
                            'field'                 => $field,
                            'field_name'            => $this -> fieldNames[$field],
                            'info'                  => '审核通过',
                            'ori_value'             => $row[$field],
                            'new_value'             => $row[$tmpField],
                            'status'                => 300,
                            'create_time'           => time(),
                            'update_time'           => time()
                        ];
                        $row -> $field = $row -> $tmpField;
                        $row -> $tmpField = null;
                    }
                }
                $row -> status = 0; // 通过
                $row -> reject_reason = '';

                Db::name('tenmillionprojectlog') -> insertAll($checkData);
            }else{
                $row -> reject_reason = $this -> request -> post('reject_reason');
                $row -> status = 200; // 驳回

                $checkData = [];
                foreach ($this->tmpFields as $tmpField) {
                    if($row -> $tmpField){
                        $row -> $tmpField = null;
                        $field = $this -> ltrim($tmpField);

                        $checkData[] = [
                            'tenmillionproject_id'  => $row['id'],
                            'tenmillionproject_name'    => $row['name'],
                            'admin_id'              => $this -> auth -> id,
                            'admin_nickname'        => $this -> auth -> nickname,
                            'field'                 => $field,
                            'field_name'            => $this -> fieldNames[$field],
                            'info'                  => $row -> reject_reason,
                            'ori_value'             => $row[$field],
                            'new_value'             => $row[$tmpField],
                            'status'                => 200,
                            'create_time'           => time(),
                            'update_time'           => time()
                        ];
                    }
                }

                Db::name('tenmillionprojectlog') -> insertAll($checkData);
            }
            $ret = $row -> save();
        }
        if($ret !== false){
            $this -> success('成功');
        }
    }

    private function ltrim($tmpField){
        if(substr($tmpField,0,4) == 'tmp_'){
            return substr($tmpField,4);
        }
    }


    public  function import() {

        if($this->request->isPost()){
            $file = $this->request->request('filepath');
            $filePath = ROOT_PATH . DS . 'public' . DS . $file;
            if (!is_file($filePath)) {
                $this->error(__('No results were found'));
            }
            //实例化reader
            $ext = pathinfo($filePath, PATHINFO_EXTENSION);
            if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
                $this->error(__('Unknown data format'));
            }
            if ($ext === 'csv') {
                $file = fopen($filePath, 'r');
                $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
                $fp = fopen($filePath, "w");
                $n = 0;
                while ($line = fgets($file)) {
                    $line = rtrim($line, "\n\r\0");
                    $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
                    if ($encoding != 'utf-8') {
                        $line = mb_convert_encoding($line, 'utf-8', $encoding);
                    }
                    if ($n == 0 || preg_match('/^".*"$/', $line)) {
                        fwrite($fp, $line . "\n");
                    } else {
                        fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
                    }
                    $n++;
                }
                fclose($file) || fclose($fp);

                $reader = new Csv();
            } elseif ($ext === 'xls') {
                $reader = new Xls();
            } else {
                $reader = new Xlsx();
            }

            //导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
            $importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';

            $table = $this->model->getQuery()->getTable();
            $database = \think\Config::get('database.database');
            $fieldArr = [];
            $list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
            foreach ($list as $k => $v) {
                $fieldArr[] = $v['COLUMN_NAME'];
                // if ($importHeadType == 'comment') {
                //     $fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
                // } else {
                //     $fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME'];
                // }
            }
            // pr($fieldArr);

            $insert = [];

            if (!$PHPExcel = $reader->load($filePath)) {
                $this->error(__('Unknown data format'));
            }

            $currentSheet = $PHPExcel->getSheet(0);  //读取文件中的第一个工作表
            // $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
            $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
            $allRow = min($allRow, 200);

            $maxColumnNumber = 11;
            $startrow = 3;
            $fields = [];
            for ($currentRow = $startrow; $currentRow <= $startrow; $currentRow++) {
                for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
                    $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
                    $val = is_object($val) ? $val->__toString() : ($val == null ? '' : trim($val));
                    if(!$this->auth->isSuperAdmin())
                    {
                        if( $val != 'name')
                            $val = 'tmp_'.$val;
                    }
                    $fields[] = $val;
                }
            }

            $msg = '';
            $errors = [];
            $addDataAll = [];
            $logDataAll = [];
            for ($currentRow = $startrow+1; $currentRow <= $allRow; $currentRow++) {
                $error = '';
                $values = [];
                for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
                    $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
                    $values[] = is_object($val) ? $val->__toString() : ($val == null ? '' : trim($val));
                }

                if($values[0] == ''){
                    continue;
                }

                $addData = [];
                $logData = [];

                $temp = array_combine($fields, $values);


                if($temp['name'] == '')
                {
                    $error .='项目名称必填<br>';
                }

                $res = [];
                foreach ($temp as $k => $v) {
                    if (in_array($k,$fieldArr) && $k !== '') {
                        $res[$k] = $v;
                    }

                    if($k == 'register_time' || $k == 'tmp_register_time'){

                        if($v && strlen($v) == 5 && is_numeric($v)){
                            $res[$k] = ($v - 25569) * 24 * 3600;
                        }
                    }
                }


                $row = $this->model -> where(['name'=> $temp['name']])->find();
                if($row) continue;

                $addData = $this->checkfileds($res,'tenmillionproject');
                if(!$this->auth->isSuperAdmin())
                {
                    $dep = $this->auth->getChargedep();
                    if($dep['group_id'] == 5){
                        $addData['street_id'] = $dep['chargedep_id'];
                        $addData['street_name'] = $dep['chargedep_name'];
                    }
                    $addData['status'] = 100;
                } else {
                    $addData['status'] = 0;
                }




                if($error =='')
                {
                    $addDataAll[] = $addData;
                }
                else{
                    $errors[] = $addData['name'].":<br>".$error;
                }
            }

            $errors_str = implode("<br>",$errors);
            if($errors_str){
                $this->error($errors_str);
            }
            $results =$this->model->allowField(true)->saveAll($addDataAll);
            if($results === false){
                $this->error('数据保存错误');
            }
            (new \app\admin\model\ProjectChecklog)->saveAll($logDataAll);
            $this->success('所有项目导入成功');
            exit();
        }
        $expurl = url('exptpl');
        $this->assign('expurl', $expurl);
        return $this->view->fetch();
    }

    public function exptpl(){
        $error_msg ='';

        $save_name = '新引进注册1000万元以上内资项目';
        $file_name = ROOT_PATH.'public/template/tenmillion.xls';


        if (! file_exists ( $file_name )) {
            header('HTTP/1.1 404 NOT FOUND');
        } else {
            $filesize = filesize($file_name);
            header("Content-type: application/vnd.ms-excel");
            header("Content-Type: application/force-download");
            header('Content-Disposition: attachment;filename="'.$save_name.'.xls"');
            header( "Content-Length: ".$filesize);
            $data = file_get_contents($file_name);
            echo $data;
        }
    }

    public function checkfileds($params,$table_name) {
        // pr($params);
        // pr($this->fiveindustryArr);
        $fields_list = Db::name('fields')->where('table_name',$table_name)->select();

        // $data = [];
        foreach ($fields_list as $key => $value) {

            if($this->auth->isSuperAdmin())
                $field = $value['item_id'];
            else
                $field = 'tmp_'.$value['item_id'];

            if(!isset($params[$field]) )
                continue;

            if($params[$field] == '')
            {
                unset($params[$field]);
                continue;
                // $params[$field] = null;
            }


            if($value['item_type'] == "select")
            {
                $params[$field] = preg_replace('/[^\x{4e00}-\x{9fa5}a-zA-Z0-9]/u',",",$params[$field]);
                $rule = json_decode($value['item_rule'], true);
                $name_field = str_replace('id','name', $field);
                $name_field_value = $params[$field];

                // echo $params[$field];
                $name_value = explode(",",$params[$field]);
                if(is_string($rule['datasource'])){
                    $tb_name = $rule['datasource'];
                    $params[$field] =  getSelectId($tb_name,$name_value);
                }else
                    $params[$field] = array_search($params[$field], $rule['datasource']);

                if(!$params[$field])
                {
                    unset($params[$field]);
                    continue;
                }

                $params[$name_field] = $name_field_value;
            }

            if($value['item_type'] == "price")
            {
                if($params[$field] == PENDING_TEXT)
                    $params[$field] = PENDING;
                if($params[$field] == ZERO )
                {
                    unset($params[$field]);
                    continue;
                }
            }
            if($value['item_type'] == "datetime" || $value['item_type'] == "date")
            {
                // var_dump($params[$field]);
                $params[$field.'_desc'] = $params[$field];
                if($params[$field] == PENDING_TEXT)
                    $params[$field] = PENDING;
                else
                    $params[$field] = dateFormatter($params[$field]);
            }

            if($value['item_type'] == 'radio')
            {
                if($params[$field] == '是')
                    $params[$field] = '1';
                elseif($params[$field] == '否')
                    $params[$field] = '1';
                else{
                    unset($params[$field]);
                    continue;
                }

            }

        }

        return $params;

    }

    public function checklog($ids = null,$field = null){
        if(!$ids || !$field){
            return $this -> error('请刷新重试');
        }

        $list = model('tenmillionprojectlog')
            -> where([
                'tenmillionproject_id'   => $ids,
                'field'                 => $field
            ])
            -> select();

        foreach ($list as &$v) {
            if(substr($v['field'],-4) == 'time' && $v['new_value'] > 0){
                $v['new_value'] = date('Y-m-d',$v['new_value']);
            }
        }
        
        $this -> assign('list',$list);
        return $this -> fetch();
    }

    public function export(){
        ini_set('memory_limit', '999M');
        $xlsName = '新注册内资项目数据导出';

        // 搜索条件
        $filter = $this->request->get("filter");
        $filter = (array)json_decode($filter, true);
        //项目名称
        if(isset($filter['name']))
            $this -> whereExtend['name'] = ['like','%'.$filter['name'].'%'];
        //投资方名称
        if(isset($filter['investment_name']))
            $this -> whereExtend['investment_name'] = ['like','%'.$filter['investment_name'].'%'];
        //投资方地区
        if(isset($filter['investment_area']))
            $this -> whereExtend['investment_area'] = ['like','%'.$filter['investment_area'].'%'];
        //是否市外
        if(isset($filter['is_out']))
            $this -> whereExtend['is_out'] = ['like','%'.$filter['is_out'].'%'];

        //注册时间
        if(isset($filter['register_time']))
        {
            $register_time = $filter['register_time'];
            $dispatchTimeArr = explode(' - ',$register_time);
            $dispatchtimeBetween = [strtotime(trim($dispatchTimeArr[0])),strtotime(trim($dispatchTimeArr[1]))];
            $this -> whereExtend[
            'register_time'
            ] = ['between',$dispatchtimeBetween];
        }

        //总投资
        if(isset($filter['investment_total'])){
            $investment_total = $filter['investment_total'];
            $investment_total_arr = explode(',',$investment_total);
            $this -> whereExtend['investment_total'] = ['between',$investment_total_arr];
        }

        //注册资本
        if(isset($filter['registered_capital'])){
            $registered_capital = $filter['registered_capital'];
            $registered_capital_arr = explode(',',$registered_capital);
            $this -> whereExtend['registered_capital'] = ['between',$registered_capital_arr];
        }

        //产业类型
        if(isset($filter['industry_type_name']))
            $this -> whereExtend['industry_type_name'] = ['like','%'.$filter['industry_type_name'].'%'];

        //所属街道
        if(isset($filter['street_name']))
            $this -> whereExtend['street_name'] = ['like','%'.$filter['street_name'].'%'];

        if(input('ids')){
            $this -> whereExtend['id'] = ['in',input('ids')];
        }

        list($where, $sort, $order, $offset, $limit) = $this->buildparams();



        $list = $this -> model
            ->where($where)
            ->where($this->whereExtend)
            ->select();

        $xlsDataReal = [];
        $xlsCell = array('序号','项目名称','经营范围','投资方名称','投资方地区','是否市外项目','注册时间','总投资','注册资本金','产业类型','占地或面积','进展状态','所属街道');
        foreach ($list as $key => $value) {
            $xlsDataReal[] = [
                ++$key,
                $value['name'],
                $value['scope_business'],
                $value['investment_name'],
                $value['investment_area'],
                $value['is_out'],
                $value['register_time_text'],
                $value['investment_total'],
                $value['registered_capital'],
                $value['industry_type_name'],
                $value['area'],
                $value['progress_status'],
                $value['street_name']
            ];
        }
        exportExcel($xlsName,'Excel2007', $xlsDataReal, $xlsCell);
    }

//
//    public function demo(){
//        $data = Db::name('zzz') -> select();
//        $dataInsert = [];
//        $street = [];
//        $streets = Db::name('chargedep') -> where('id','<',9) -> select();
//        foreach ($streets as $v){
//            $street[$v['name']] = $v['id'];
//        }
//        foreach ($data as $key => $v){
//            if(strlen($v['g']) == 6){
//                $v['g'] = $v['g'].'01';
//            }
//
//
//
//            $d = [
//                'name'  => $v['b'],
//                'scope_business'    => $v['c'],
//                'investment_name'   => $v['d'],
//                'investment_area'   => $v['e'],
//                'is_out'            => $v['f'] == '是' ? '1' : '0',
//                'register_time'     => strtotime($v['g']),
//                'register_time_desc'    => date('Y-m-d',strtotime($v['g'])),
//                'investment_total'  => intval($v['h']) > 0 ? intval($v['h']) : '0',
//                'registered_capital'    => $v['i'],
//                'industry_type_name'    => $v['j'],
//                'street_id'         => $street[$v['k']],
//                'street_name'       => $v['k'],
//                'create_time'       => time(),
//                'update_time'       => time()
//            ];
//            $dataInsert[] = $d;
//        }
//
//        Db::name('tenmillionproject') -> insertAll($dataInsert);
//
//    }

}
